package com.ubxtech.jdk21.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;

/**
 * @author Victor.Xiao
 * @since 2022-03-30 10:29
 * spring-boot 3.2 MqttPahoMessageDrivenChannelAdapter.doStart()和2.6版本不一样
 * 连接失败不会报错,不提示任何信息,2.6会报错
 **/
@Slf4j
@Component
public class MultiReceiveMessageCustomerHandler implements MessageHandler {

    @ServiceActivator(inputChannel = "channel1")
    @Override
    public void handleMessage(Message<?> message) throws MessagingException {
        log.info("收到mqtt消息11111:{}", message);
        String payload = String.valueOf(message.getPayload());
        MessageHeaders headers = message.getHeaders();
        String topic = String.valueOf(headers.get("mqtt_receivedTopic"));
    }

    @ServiceActivator(inputChannel = "channel2")
    public void handleMessage2(Message<?> message) throws MessagingException {
        log.info("收到mqtt消息2222:{}", message);
    }

}
